home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 October / maximum-cd-2009-10.iso / DiscContents / Firefox Setup 3.5.exe / nonlocalized / chrome / toolkit.jar / content / mozapps / extensions / list.js < prev    next >
Encoding:
Text File  |  2009-06-24  |  5.8 KB  |  160 lines

  1. //@line 39 "e:\builds\moz2_slave\win32_build\build\toolkit\mozapps\extensions\content\list.js"
  2.  
  3. const kXULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
  4. const kDialog = "dialog";
  5.  
  6. /**
  7.  * This dialog can be initialized from parameters supplied via window.arguments
  8.  * or it can be used to display blocklist notification and blocklist blocked
  9.  * installs via nsIDialogParamBlock as is done by nsIExtensionManager.
  10.  *
  11.  * When using this dialog with window.arguments it must be opened modally, the
  12.  * caller can inspect the user action after the dialog closes by inspecting the
  13.  * value of the |result| parameter on this object which is set to the dlgtype
  14.  * of the button used to close the dialog.
  15.  * 
  16.  * window.arguments[0] is an array of strings to display in the tree. If the
  17.  * array is empty the tree will not be displayed.
  18.  * window.arguments[1] a JS Object with the following properties:
  19.  * 
  20.  * title:    A title string, to be displayed in the title bar of the dialog.
  21.  * message1: A message string, displayed above the addon list
  22.  * message2: A message string, displayed below the addon list
  23.  * message3: A bolded message string, displayed below the addon list
  24.  * moreInfoURL: An url for displaying more information
  25.  * iconClass  : Can be one of the following values (default is alert-icon)
  26.  *              alert-icon, error-icon, or question-icon
  27.  *
  28.  * If no value is supplied for message1, message2, message3, or moreInfoURL,
  29.  * the element is not displayed.
  30.  *
  31.  * buttons: {
  32.  *  accept: { label: "A Label for the Accept button",
  33.  *            focused: true },
  34.  *  cancel: { label: "A Label for the Cancel button" },
  35.  *  ...
  36.  * },
  37.  *
  38.  * result:  The dlgtype of button that was used to dismiss the dialog. 
  39.  */
  40.  
  41. var gButtons = { };
  42.  
  43. function init() {
  44.   var de = document.documentElement;
  45.   var items = [];
  46.   if (window.arguments[0] instanceof Components.interfaces.nsIDialogParamBlock) {
  47.     // This is a warning about a blocklisted item the user is trying to install
  48.     var args = window.arguments[0];
  49.     var softblocked = args.GetInt(0) == 1 ? true : false;
  50.  
  51.     var extensionsBundle = document.getElementById("extensionsBundle");
  52.     try {
  53.       var formatter = Components.classes["@mozilla.org/toolkit/URLFormatterService;1"]
  54.                                 .getService(Components.interfaces.nsIURLFormatter);
  55.       var url = formatter.formatURLPref("extensions.blocklist.detailsURL");
  56.     }
  57.     catch (e) { }
  58.  
  59.     var params = {
  60.       moreInfoURL: url,
  61.     };
  62.  
  63.     if (softblocked) {
  64.       params.title = extensionsBundle.getString("softBlockedInstallTitle");
  65.       params.message1 = extensionsBundle.getFormattedString("softBlockedInstallMsg",
  66.                                                            [args.GetString(0)]);
  67.       var accept = de.getButton("accept");
  68.       accept.label = extensionsBundle.getString("softBlockedInstallAcceptLabel");
  69.       accept.accessKey = extensionsBundle.getString("softBlockedInstallAcceptKey");
  70.       de.getButton("cancel").focus();
  71.       document.addEventListener("dialogaccept", allowInstall, false);
  72.     }
  73.     else {
  74.       params.title = extensionsBundle.getString("blocklistedInstallTitle2");
  75.       params.message1 = extensionsBundle.getFormattedString("blocklistedInstallMsg2",
  76.                                                            [args.GetString(0)]);
  77.       de.buttons = "accept";
  78.       de.getButton("accept").focus();
  79.     }
  80.   }
  81.   else {
  82.     items = window.arguments[0];
  83.     params = window.arguments[1];
  84.   }
  85.  
  86.   var addons = document.getElementById("addonsChildren");
  87.   if (items.length > 0)
  88.     document.getElementById("addonsTree").hidden = false;
  89.  
  90.   // Fill the addons list
  91.   for (var i = 0; i < items.length; ++i) {
  92.     var treeitem = document.createElementNS(kXULNS, "treeitem");
  93.     var treerow  = document.createElementNS(kXULNS, "treerow");
  94.     var treecell = document.createElementNS(kXULNS, "treecell");
  95.     treecell.setAttribute("label", items[i]);
  96.     treerow.appendChild(treecell);
  97.     treeitem.appendChild(treerow);
  98.     addons.appendChild(treeitem);
  99.   }
  100.  
  101.   // Set the messages
  102.   var messages = ["message1", "message2", "message3"];
  103.   for (i = 0; i < messages.length; ++i) {
  104.     if (messages[i] in params) {
  105.       var message = document.getElementById(messages[i]);
  106.       message.hidden = false;
  107.       message.appendChild(document.createTextNode(params[messages[i]]));
  108.     }
  109.   }
  110.   
  111.   document.getElementById("infoIcon").className =
  112.     params["iconClass"] ? "spaced " + params["iconClass"] : "spaced alert-icon";
  113.  
  114.   if ("moreInfoURL" in params && params["moreInfoURL"]) {
  115.     message = document.getElementById("moreInfo");
  116.     message.value = extensionsBundle.getString("moreInfoText");
  117.     message.setAttribute("href", params["moreInfoURL"]);
  118.     document.getElementById("moreInfoBox").hidden = false;
  119.   }
  120.  
  121.   // Set the window title
  122.   if ("title" in params)
  123.     document.title = params.title;
  124.  
  125.   // Set up the buttons
  126.   if ("buttons" in params) {
  127.     gButtons = params.buttons;
  128.     var buttonString = "";
  129.     for (var buttonType in gButtons)
  130.       buttonString += "," + buttonType;
  131.     de.buttons = buttonString.substr(1);
  132.     for (buttonType in gButtons) {
  133.       var button = de.getButton(buttonType);
  134.       button.label = gButtons[buttonType].label;
  135.       if (gButtons[buttonType].focused)
  136.         button.focus();
  137.       document.addEventListener(kDialog + buttonType, handleButtonCommand, true);
  138.     }
  139.   }
  140. }
  141.  
  142. function shutdown() {
  143.   for (var buttonType in gButtons)
  144.     document.removeEventListener(kDialog + buttonType, handleButtonCommand, true);
  145. }
  146.  
  147. function allowInstall() {
  148.   var args = window.arguments[0];
  149.   args.SetInt(1, 1);
  150. }
  151.  
  152. /**
  153.  * Watch for the user hitting one of the buttons to dismiss the dialog
  154.  * and report the result back to the caller through the |result| property on
  155.  * the arguments object.
  156.  */
  157. function handleButtonCommand(event) {
  158.   window.arguments[1].result = event.type.substr(kDialog.length);
  159. }
  160.